package com.yan.demo.array;

// 0 1 2 3 4 5 6 7 8 9
// 数组反转
public class ArrayDemo3 {
    public static void main1(String[] args) {
        int[] arr = {5, 12, 90, 18, 77, 76, 45, 28, 59, 72};
        for (int start = 0, end = arr.length - 1; start <= end; start++, end--) {
            int temp;
            temp = arr[start];
            arr[start] = arr[end];
            arr [end] = temp;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
// 创建新数组
    public static void main2(String[] args) {
        int[] arr = {5, 12, 90, 18, 77, 76, 45, 28, 59, 72};
        int[] arr1 = new int[10];
        for (int i = arr.length - 1; i >= 0; i--) {
            int temp = arr1[arr1.length-1 - i];
            arr1[arr1.length-1 - i] = arr[i];
            arr[i] = arr1[arr1.length-1 - i];
        }
        for (int i = 0; i < arr1.length; i++) {
            System.out.print(arr1[i] + " ");
        }
    }
// 单索引
    public static void main(String[] args) {
        int[] arr = {5, 12, 90, 18, 77, 76, 45, 28, 59, 72};
        for (int i = 0; i < (arr.length - 1) / 2 ; i++) {
            int temp;
            temp = arr[i];
            arr[i] = arr[arr.length -1 - i];
            arr[arr.length -1 - i] = temp;
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}
